package serializable;

import java.io.*;

public class MultiSaveSameObj implements Serializable {
    private static final long serialVersionUID = 1L;

    static class Test2 implements Serializable{
        private static final long serialVersionUID = 1L;
        public int i;
    }

    public static void main(String[] args) throws Exception {
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("result.obj"));
        Test2 test = new Test2();
        test.i = 1;
        out.writeObject(test);
        out.flush();
        test.i = 2;
        out.writeObject(test);
        out.close();
        ObjectInputStream oin = new ObjectInputStream(new FileInputStream(
                "result.obj"));
        Test2 t1 = (Test2) oin.readObject();
        Test2 t2 = (Test2) oin.readObject();
        System.out.println(t1.i);
        System.out.println(t2.i);
    }
}
